﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Rbac_APi.Application.Command.Rule;
using T_Rbac_APi.Application.CommandHandler.RuleHandler;

namespace T_Rbac_APi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RulesController : ControllerBase
    {
        private readonly IMediator mediator;

        public RulesController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加角色信息
        /// </summary>
        /// <param name="ruleAddHandler"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddRule(RuleAddCommand ruleAddHandler)
        {
            ruleAddHandler.CreateBy = "小明";
            ruleAddHandler.CreateDate=DateTime.Now;
            ruleAddHandler.IsDel = false;
            return await mediator.Send(ruleAddHandler);
        }
        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="ruleDeleteCommand"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteRule([FromQuery] RuleDeleteCommand ruleDeleteCommand)
        {

            return await mediator.Send(ruleDeleteCommand);
        }
        /// <summary>
        /// 更新角色信息
        /// </summary>
        /// <param name="ruleUpdateCommand"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateRule(RuleUpdateCommand ruleUpdateCommand)
        {
            ruleUpdateCommand.UpdateDate = DateTime.Now;
            ruleUpdateCommand.UpdateBy = "小红";
            return await mediator.Send(ruleUpdateCommand);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ruleDeleteListCommand"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteListByid([FromQuery]RuleDeleteListCommand ruleDeleteListCommand)
        {
            return await mediator.Send(ruleDeleteListCommand);
        }
    }
}
